﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;
using System.Text;

namespace SistemasBuenosAires.Website.Controls.Map
{
    public partial class Map : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            Initialize();
        }

        #region PROPERTIES

        public String Width
        {
            set { DivMap.Style.Add("width", value); }
        }

        public String Height
        {
            set { DivMap.Style.Add("height", value); }
        }

        private Double _latitude;

        public Double Latitude
        {
            get { return _latitude; }
            set { _latitude = value; }
        }

        private Double _longitude;

        public Double Longitude
        {
            get { return _longitude; }
            set { _longitude = value; }
        }

        #endregion

        protected void Initialize()
        {
            RegisterScript();
        }

        protected void RegisterScript()
        {
            var script = new StringBuilder();
            var streamReader = new StreamReader(Request.PhysicalApplicationPath + "/Controls/Map/Map.js");
            streamReader.ReadLine();
            script.AppendLine(streamReader.ReadToEnd());
            script.Replace("##Lat", "-34.624592");
            script.Replace("##Lng", "-58.419136");

            var clientScript = Page.ClientScript;
            if (!clientScript.IsStartupScriptRegistered("MapScript"))
            {
                clientScript.RegisterStartupScript(this.GetType(), "MapScript", script.ToString(), true);
            }
        }
    }
}